package com.itheima.socketdemo7;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10002);

        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        OutputStream os = accept.getOutputStream();
        String msg = "你是谁？";
//        os.write(msg.getBytes(StandardCharsets.UTF_8));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
        bw.write(msg);
        bw.newLine();
        bw.flush();

        bw.close();
        is.close();
        os.close();
        accept.close();
        ss.close();
    }
}
